﻿@model CategoriesTreeControlViewModel
<script type="text/javascript">
    $(document).ready(function () {
        initializeParentCategoriesTree();
    });

    function initializeParentCategoriesTree() {
        var mainDynoTree = $("#treeParentCategories").dynatree({
            onSelect: function (flag, dtnode) {
                //                console.warn(dtnode.tree.getSelectedNodes()[0].data);
                // This will happen each time a check box is selected/deselected
                var selectedNode = dtnode.tree.getSelectedNodes()[0];

                if (selectedNode) {
                    $("#newParentCategoryId").val(selectedNode.data.key);
                }
                else {
                    $("#newParentCategoryId").val("");
                }
            },
            selectMode: 1,
            checkbox: true,
            classNames: { nodeIcon: "" }
        });

        mainDynoTree.dynatree("getRoot").visit(function (node) {
            node.expand(true);
        });
    }

</script>
<div id="treeParentCategories">
    @Html.CategoryTree(Model.Categories, false, Model.ExcludCategoryId)
</div>
